﻿using Dapper;
using Domain.Entity;
using Domain.IRepository;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EFCore.Repository
{
	public class CFFKRepository : ICFFKRepository
	{
		private readonly MyDbContext myDbContext;

		public CFFKRepository(MyDbContext myDbContext)
		{
			this.myDbContext = myDbContext;
		}

        public List<CFFK> GetCFFK()
		{
			string sql = "select * from CFFK";
			return myDbContext.CFFK.FromSqlRaw(sql).ToList();
		}

		public List<CFFK> GetfirstKindId()
		{
			string sql = "SELECT MAX(FfkId) AS FfkId FROM dbo.CFFK";

			return myDbContext.CFFK.FromSqlRaw(sql).ToList();
        }
        public bool AddCFKK(CFFK cFFK)
        {
			string sql = $"insert into dbo.CFFK(FirstKindId, FirstKindName, FirstKindSalaryId, FirstKindSaleId) values({cFFK.FirstKindId},'{cFFK.FirstKindName}',{cFFK.FirstKindSalaryId},{cFFK.FirstKindSaleId})";
			return myDbContext.Database.ExecuteSqlRaw(sql) > 0;
        }
		public bool updateCFFK(CFFK cFFK)
		{
            string sql = $"update dbo.CFFK set FirstKindId={cFFK.FirstKindId}, FirstKindName='{cFFK.FirstKindName}', FirstKindSalaryId={cFFK.FirstKindSalaryId}, FirstKindSaleId={cFFK.FirstKindSaleId} WHERE FfkId={cFFK.FfkId}";
            return myDbContext.Database.ExecuteSqlRaw(sql) > 0;
        }
		public bool DeleteCFFK(CFFK cFFK)
		{
            string sql = $"Delete from dbo.CFFK where FfkId={cFFK.FfkId}";
            return myDbContext.Database.ExecuteSqlRaw(sql) > 0;
        }
    }

}
